<?php 

namespace app\bee\controller;
use think\Controller;
use think\Cache;
use \DOMDocument;
use \DateTime;

class Target extends BeeController {
  function getProducts($url, $type = '') {
    if ($type == 'json') {
      // var_dump(file_exists(APP_PATH . '../public/upload/brands/gerber/target.json'));
      $datafile = APP_PATH . '../public/upload/brands/gerber/target.json';
      if (file_exists($datafile)) {
        $json = file_get_contents($datafile); // forbidden
        $data = json_decode($json, TRUE);
        return $data['search_response']['items']['Item'];
      }
      
      // $json = $this->request($url);
      // $data = json_decode($json, TRUE);
      // var_dump($json);
    }
//     $response = $this->request($url);
    
//     // 兼容 HTML 错误语法
//     libxml_use_internal_errors(true);
    
//     $doc->loadHTML($response);
    return "(no products)";
  }
}